//
//  FinallyViewController.swift
//  E-CycleForShop
//
//  Created by enghou on 17/4/17.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class FinallyViewController: BaseViewController {

    var price = ""
    var number = 10000
    var param : Dictionary<String,String> = [:]
    override func viewDidLoad() {
        super.viewDidLoad()
        self.naviHide = false
        self.defaultBackButton()
        self.title = "立即结算"
        self.view.backgroundColor = UIColor.colorWithHexString(hex: "f8f8f8")
        configPriceBlock()
        // Do any additional setup after loading the view.
    }

    func configPriceBlock() -> Void {
//        let label = UILabel.init()
//        label.backgroundColor = UIColor.white
//        label.layer.cornerRadius = YXButtonCorner
//        label.layer.borderWidth = YXHeightScale
//        label.layer.borderColor = UIColor.colorWithHexString(hex: "dfdfdf").cgColor
//        let string = "结算价: ¥" + price
//        let attributedString = NSMutableAttributedString.init(string: string)
//        attributedString.addAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 30 * YXWidthScale),NSForegroundColorAttributeName : UIColor.black], range: NSRange.init(location: 0, length: string.characters.count))
//        attributedString.addAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 60 * YXWidthScale)], range: NSRange.init(location: 4, length: string.characters.count - 4))
//        label.attributedText = attributedString
//        label.frame = CGRect.init(x: 30 * YXWidthScale, y: 20 * YXHeightScale, width: YXDeviceWidth - 60 * YXWidthScale, height: 178 * YXHeightScale)
//        label.textAlignment = .center
//        self.view.addSubview(label)
//        
//        
//        let tray = UIView.init()
//        tray.backgroundColor = UIColor.white
//        tray.layer.cornerRadius = YXButtonCorner
//        tray.layer.borderWidth = YXHeightScale
//        tray.layer.borderColor = UIColor.colorWithHexString(hex: "dfdfdf").cgColor
//        tray.frame = CGRect.init(x: label.left(), y: label.bottom() + 20 * YXHeightScale, width: YXDeviceWidth - 60 * YXWidthScale, height: 178 * YXHeightScale)
//        self.view.addSubview(tray)
//        
//        let secondLabel = UILabel.init()
//        secondLabel.backgroundColor = UIColor.white
//        secondLabel.frame = CGRect.init(x: label.left(), y: 20 * YXHeightScale, width: YXDeviceWidth - 60 * YXWidthScale, height: 178 * YXHeightScale)
//        secondLabel.textAlignment = .left
//        secondLabel.numberOfLines = 0
//        let num = String(number)
//        let targetString = "您是第" + num + "位\n用大象回收检测该手机的用户,\n感谢您对绿色环保做出的一份贡献."
//        let attributeStr = NSMutableAttributedString.init(string: targetString)
//        attributeStr.addAttributes([NSForegroundColorAttributeName : UIColor.colorWithHexString(hex: "666666"),NSFontAttributeName : UIFont.systemFont(ofSize: 32 * YXWidthScale)], range: NSRange.init(location: 0, length: targetString.characters.count))
//        attributeStr.addAttributes([NSForegroundColorAttributeName : UIColor.colorWithHexString(hex: "ee2f2f")], range: NSRange.init(location: 3, length: num.characters.count))
//        secondLabel.attributedText = attributeStr
//        secondLabel.configLineSpacing(space: 8 * YXHeightScale)
//        tray.addSubview(secondLabel)
//        
//        let cancel = UIButton.init(type: .system)
//        cancel.setTitle("取消", for: .normal)
//        cancel.titleLabel?.font = UIFont.boldSystemFont(ofSize: 36 * YXWidthScale)
//        cancel.backgroundColor = UIColor.white
//        cancel.setTitleColor(UIColor.black, for: .normal)
//        cancel.layer.cornerRadius = YXButtonCorner
//        cancel.layer.borderColor = UIColor.colorWithHexString(hex: "dfdfdf").cgColor
//        cancel.layer.borderWidth = YXHeightScale
//        cancel.frame = CGRect.init(x: secondLabel.left(), y: tray.bottom() + 40 * YXHeightScale, width: 325 * YXWidthScale, height: 80 * YXHeightScale)
//        cancel.addTarget(self, action: #selector(pops), for: .touchUpInside)
//        self.view.addSubview(cancel)
//        
//        let confirm = UIButton.init(type: .system)
//        confirm.setTitle("确定", for: .normal)
//        confirm.titleLabel?.font = UIFont.boldSystemFont(ofSize: 36 * YXWidthScale)
//        confirm.backgroundColor = UIColor.black
//        confirm.setTitleColor(UIColor.white, for: .normal)
//        confirm.layer.cornerRadius = YXButtonCorner
//        confirm.layer.borderColor = UIColor.colorWithHexString(hex: "dfdfdf").cgColor
//        confirm.frame = CGRect.init(x: cancel.right() + 18 * YXWidthScale, y: tray.bottom() + 40 * YXHeightScale, width: 325 * YXWidthScale, height: 80 * YXHeightScale)
//        confirm.addTarget(self, action: #selector(settleAccounts), for: .touchUpInside)
//        self.view.addSubview(confirm)
        
    }
    
    func settleAccounts() -> Void {
        //接口
        self.beginAnim()
        for key in param.keys {
            if param[key] == nil {
                return
            }
        }
        Manager.shared().addCompletedOrder(param: param, success: {(mod) in
            self.endAnim()
            if mod.result == true {
                SimpleAlertView.show(dismissBlock: {
                    let information = GetInformationViewController.init()
                    information.param = self.param
                    self.navigationController?.pushViewController(information, animated: true)
                },superView: self.view)
            } else {
                self.commonAlertMsg(content: mod.msg)
            }
        }, fail: {(code) in
            self.commonAlertMsg(content: YXNetWorkFail)
        })
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
